//
//  UITableView+OATableConfig.m
//  OASDK_Works
//
//  Created by ChenJie on 3/29/20.
//  Copyright © 2020 Mist. All rights reserved.
//

#import "UITableView+OATableConfig.h"
#import <objc/runtime.h>

@implementation UITableView (OATableConfig)

/* Property: oa_tableConfig */
- (OATableConfig *)oa_tableConfig {
    OATableConfig *tableConfig = objc_getAssociatedObject(self, _cmd);
    if (!tableConfig) {
        tableConfig = [OATableConfig new];
        self.oa_tableConfig = tableConfig;
        self.dataSource = self.oa_dataSourceImplementation;
        self.delegate = self.oa_delegateImplementation;
        
        tableConfig.tableView = self;
    }
    return tableConfig;
}

- (void)oa_setTableConfig:(OATableConfig *)oa_tableConfig {
    objc_setAssociatedObject(self, @selector(oa_tableConfig), oa_tableConfig, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

/* Property: oa_dataSourceImplementation */
- (OATableDataSource *)oa_dataSourceImplementation {
    OATableDataSource *dataSourceImplementation = objc_getAssociatedObject(self, _cmd);
    if (!dataSourceImplementation) {
        dataSourceImplementation = [OATableDataSource new];
        self.oa_dataSourceImplementation = dataSourceImplementation;
    }
    return dataSourceImplementation;
}

- (void)oa_setDataSourceImplementation:(OATableDataSource *)oa_dataSourceImplementation {
    objc_setAssociatedObject(self, @selector(oa_dataSourceImplementation), oa_dataSourceImplementation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

/* Property: oa_delegateImplementation */
- (OATableDelegate *)oa_delegateImplementation {
    OATableDelegate *delegateImplementation = objc_getAssociatedObject(self, _cmd);
    if (!delegateImplementation) {
        delegateImplementation = [OATableDelegate new];
        self.oa_delegateImplementation = delegateImplementation;
    }
    return delegateImplementation;
}

- (void)oa_setDelegateImplementation:(OATableDelegate *)oa_delegateImplementation {
    objc_setAssociatedObject(self, @selector(oa_delegateImplementation), oa_delegateImplementation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

@end
